package com.kehutong.webchat.admin;

import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

import com.kehutong.common.util.Token;
import com.kehutong.webchat.entity.WeChatSetting;
import com.kehutong.webchat.service.WeChatSettingService;

/**
 * 
 * @author: Kaplan
 * @version: v1.0
 * @description: 
 * @date:2021年6月3日
 */
@MvcAction
@ReqMapping("/admin/wechat/setting/manage")
public class WeChatSettingController {
	
	@Inject
	private WeChatSettingService weChatSettingService;
	
	
	
	/**
	 * 
	 * @author: Kaplan
	 * @version: v1.0
	 * @description: 新增
	 * @date:2021年6月3日
	 * @param weChatSetting
	 */
	@HasPermission("wechat:setting:manage:save")
	@ReqMapping("/save")
	@Bean(newInstance = true,copy = true)
	public Object save(WeChatSetting weChatSetting,Token token) {
		try {
			weChatSetting.setId(weChatSetting.getAppId());
			weChatSettingService.save(weChatSetting);
			return Result.success();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Result.error(500, "添加失败，后台服务器错误");
	}
	
	/**
	 * 
	 * @author: Kaplan
	 * @version: v1.0
	 * @description: 删除
	 * @date:2021年6月3日
	 * @param id
	 */
	@HasPermission("wechat:setting:manage:delete")
	@ReqMapping("/delete")
	public Object delete(String id) {
		try {
			weChatSettingService.delete(id);
			return Result.success();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Result.error(500, "删除失败，后台服务器错误");
	}
	
	/**
	 * 
	 * @author: Kaplan
	 * @version: v1.0
	 * @description: 修改
	 * @date:2021年6月3日
	 * @param weChatSetting
	 */
	@HasPermission("wechat:setting:manage:edit")
	@ReqMapping("/update")
	@Bean(copy = true)
	public Object update(WeChatSetting weChatSetting) {
		try {
			weChatSettingService.update(weChatSetting);
			return Result.success();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Result.error(500, "修改失败，后台服务器错误");
	}
	
	/**
	 * 
	 * @author: Kaplan
	 * @version: v1.0
	 * @description: 根据ID查询	
	 * @date:2021年6月3日
	 * @param id
	 * @return
	 */
	@HasPermission("wechat:setting:manage")
	@ReqMapping("/get")
	public Object get(String id) {
		return Result.success(weChatSettingService.get(id));
	}
	
	/**
	 * 
	 * @author: Kaplan
	 * @version: v1.0
	 * @description: 分页查询
	 * @date:2021年6月3日
	 * @param jsonObject
	 * @return
	 */
	@HasPermission("wechat:setting:manage")
	@ReqMapping("/page")
	public Object page(JSONObject jsonObject) {
		return Result.success(weChatSettingService.page(jsonObject));
	}
}
